package com.yl.wzy.banner;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;

import com.danikula.videocache.HttpProxyCacheServer;
import com.yl.wzy.MApplication;
import com.yl.wzy.R;

import java.util.ArrayList;
import java.util.List;

public class BannerActivity extends AppCompatActivity {

    private YLBanner banner;
    private List<String> list;
    private String proxyUrl;
    private String proxyUrl2;
    private String placeholder = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556519419528&di=0f9227b70f37223d27c3d66c0c5c2eb6&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fpic%2F5%2Fa5%2F6a00463441.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.yl.wzy.R.layout.activity_banner);

        banner = (YLBanner) findViewById(R.id.banner);

        DisplayMetrics metrics = getResources().getDisplayMetrics();
        ViewGroup.LayoutParams params = banner.getLayoutParams();

        if (params != null)   //  设置轮播高度
        {
            params.height = metrics.widthPixels;
        }

        initData();
        initView();
    }

    private void initData() {
        HttpProxyCacheServer proxy = MApplication.getProxy(getApplicationContext());
        proxyUrl = proxy.getProxyUrl("http://st.chaoyindj.com/zwmtv2016/%E7%83%AD%E8%88%9E-%E5%B9%B2%E5%B0%B1%E5%AE%8C%E4%BA%86.mp4");
//        proxyUrl2 = proxy.getProxyUrl("http://st.chaoyindj.com/zwmtv2016/%E7%83%AD%E8%88%9E-%E6%80%A7%E6%84%9F%E5%A5%B3%E5%A3%B0-%E4%BB%8A%E5%A4%9C%E4%BD%A0%E4%BC%9A%E4%B8%8D%E4%BC%9A%E6%83%B3%E8%B5%B7%E6%88%91-DJ%E4%BD%95%E9%B9%8F%E7%89%88.mp4");

        list = new ArrayList<>();
        list.add(proxyUrl);
        list.add(proxyUrl2);
        list.add("http://img2.imgtn.bdimg.com/it/u=3817131034,1038857558&fm=27&gp=0.jpg");
        list.add("http://img1.imgtn.bdimg.com/it/u=4194723123,4160931506&fm=200&gp=0.jpg");
        list.add("http://img5.imgtn.bdimg.com/it/u=1812408136,1922560783&fm=27&gp=0.jpg");
    }

    private void initView() {
        banner.setDataList(list,placeholder);
        banner.setImgDelayed(5000);
        banner.startBanner();
//        banner.startAutoPlay();

    }

    @Override
    protected void onDestroy() {
        banner.destroy();
        super.onDestroy();
    }
}